package decorator;

/**
 * 游戏物体
 */
abstract class GameObject{
    abstract void paint();
}

/**
 * 坦克
 */
class Tank extends GameObject{
    void paint(){
        System.out.println("tank");
    }
}

/**
 * 子弹
 */
class Bullet extends GameObject{

    @Override
    void paint() {
        System.out.println("bullet");
    }
}

/**
 * 游戏物体装饰器,不限制是什么物体
 */
abstract class GameObjectDecorator extends GameObject{
    GameObject gameObject;
}

/**
 * 血槽的装饰器
 */
class Blood extends GameObjectDecorator{
    Blood(GameObject gameObject){
        this.gameObject = gameObject;
    }
    @Override
    void paint() {
        System.out.println("血槽");

        gameObject.paint();
    }
}

/**
 * 装甲的装饰器
 */
class Armor extends GameObjectDecorator{
    Armor(GameObject gameObject){
        this.gameObject = gameObject;
    }
    @Override
    void paint() {
        System.out.println("装甲");

        gameObject.paint();
    }
}

public class Decorator {
    public static void main(String[] args) {
        GameObject tank = new Tank();
        GameObject bullet = new Bullet();

        GameObjectDecorator blood = new Blood(tank);
        GameObjectDecorator armor = new Armor(bullet);

        blood.paint();
        armor.paint();

        // 加上血槽和装甲 给bullet
        GameObjectDecorator ext = new Blood(new Armor(new Bullet()));
        ext.paint();

    }
}
